import requests
import coo
import 查询事项信息


class upData:
    cookies = coo.cookies
    headers = coo.headers
    ur = '59.215.206.188'
    dispatch = 'ddglzy'
    def updata(self, name, regCode):


        queryRe = 查询事项信息.查询事项信息().query(name, regCode)

        for i in queryRe:

            url = 'http://{}/{}/dispatch/resourse/itemconfigure?method=save'.format(self.ur, self.dispatch)
            备案类事项 = {"id": "{}".format(i[10]), "itemId": "{}".format(i[0]),
                          "itemCode": "{}".format(i[2]),
                          "areaCode": "{}".format(i[6]), "areaName": "{}".format(i[7]),
                          "itemTime": "{}".format(i[8]),
                          "organName": "{}".format(i[4]), "organCode": "{}".format(i[5]),
                          "exchangeCode": "{}".format(i[1]),
                          "sysInfo": [
                              {
                                  "sysId": "A7875618DB3B46F1993D91BA606B582A",
                                  "sysType": "dispatch",
                                  "sysName": "产品调度系统3.5"
                              },
                              {
                                  "sysType": "queuing",
                                  "sysName": ""
                              },
                              {
                                  "sysType": "punlish",
                                  "sysName": ""
                              },
                              {
                                  "sysId": "74AAC186781B42099DD1E0639A772E2F",
                                  "sysType": "online",
                                  "sysName": "网厅网上申报系统"
                              },
                              {
                                  "sysType": "hallManager",
                                  "sysName": ""
                              },
                              {
                                  "sysId": "F2CB256C327B423BB034220F522769AA",
                                  "sysType": "accept",
                                  "sysName": "综合受理产品3.5"
                              },
                              {
                                  "sysId": "9D7FD79D91014AF6A06CBEF4A919D87F",
                                  "sysType": "approve",
                                  "sysName": "贵州省医疗保障信息系统（备案类事项）"
                              }
                          ]}
            二类事项 = {"id": "{}".format(i[10]), "itemId": "{}".format(i[0]),
                        "itemCode": "{}".format(i[2]),
                        "areaCode": "{}".format(i[6]), "areaName": "{}".format(i[7]),
                        "itemTime": "{}".format(i[8]),
                        "organName": "{}".format(i[4]), "organCode": "{}".format(i[5]),
                        "exchangeCode": "{}".format(i[1]),
                        "sysInfo": [
                            {
                                "sysId": "A7875618DB3B46F1993D91BA606B582A",
                                "sysType": "dispatch",
                                "sysName": "产品调度系统3.5"
                            },
                            {
                                "sysType": "queuing",
                                "sysName": ""
                            },
                            {
                                "sysType": "punlish",
                                "sysName": ""
                            },
                            {
                                "sysId": "74AAC186781B42099DD1E0639A772E2F",
                                "sysType": "online",
                                "sysName": "网厅网上申报系统"
                            },
                            {
                                "sysType": "hallManager",
                                "sysName": ""
                            },
                            {
                                "sysId": "F2CB256C327B423BB034220F522769AA",
                                "sysType": "accept",
                                "sysName": "综合受理产品3.5"
                            },
                            {
                                "sysId": "893BB2D3393148D0B425C1084A26BA7F",
                                "sysType": "approve",
                                "sysName": "贵州省医疗保障信息系统（二类事项）"
                            }
                        ]}

            二类 = ['单位新参保登记',
                    '单位暂停参保',
                    '单位注销登记',
                    '职工参保登记——增加',
                    '职工参保登记——中断',
                    '职工参保登记——终止',
                    '职工参保登记——恢复',
                    '职工参保登记——在职转退休',
                    '灵活就业人员基本医疗保险参保登记——增加',
                    '灵活就业人员基本医疗保险参保登记——中断',
                    '城乡居民参保登记',
                    '单位参保信息变更登记',
                    '职工参保信息变更登记',
                    '城乡居民暂停参保登记',
                    '城乡居民参保信息变更登记',
                    '参保人员个人账户一次性支取',
                    '转移接续手续办理',
                    '基本医疗保险参保人员享受门诊慢特病病种待遇认定-申办',
                    '基本医疗保险参保人员享受门诊慢特病病种待遇认定-变更医疗机构',
                    '基本医疗保险城乡居民参保人员享受门诊慢特病病种待遇认定-申办',
                    '基本医疗保险城乡居民参保人员享受门诊慢特病病种待遇认定-变更医疗机构',
                    '门诊费用报销-普通门诊',
                    '门诊费用报销-门诊慢特病',
                    '住院费用报销',
                    '产前检查费支付',
                    '生育医疗费支付',
                    '计划生育医疗费支付',
                    '生育津贴支付',
                    '医疗救助对象手工（零星）报销']

            if i[9] in 二类:
                表单 = 二类事项
            else:
                表单 = 备案类事项
            try:
                x = requests.post(url, json=表单, cookies=self.cookies, headers=self.headers).json()

                返回结果 = i[7] + ">" + i[3] + "****" + i[-2] + "****" + str(x['statusCode'])
                print(返回结果)
            except:
                print(返回结果)
                返回结果 = (i[7] + ">" + i[3] + "存在异常")


            # return 返回结果